#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int n;
struct Institution{
    string code;
    int scoreA = 0,scoreB = 0,scoreT = 0;
    int sum,num = 0;
};
map<string,Institution> ma;
vector<Institution> v;

int cmp(Institution &i1,Institution &i2){
    if(i1.sum==i2.sum){
        if(i1.num==i2.num)
            return i1.code<i2.code;
        return i1.num<i2.num;
    }
    return i1.sum>i2.sum;
}

signed main()
{
    cin>>n;
    for(int i=0;i<n;i++){
        string id,code;
        int score;
        cin>>id>>score>>code;
        for(int j=0;j<code.size();j++){
            if(code[j]>='A'&&code[j]<='Z')    code[j] += 32;
        }
        ma[code].code = code;
        ma[code].num++;
        if(id[0]=='B')    ma[code].scoreB += score;
        else if(id[0]=='A')    ma[code].scoreA += score;
        else if(id[0]=='T')    ma[code].scoreT += score;
    }
    for(auto it:ma){
        it.second.sum = it.second.scoreB/1.5+it.second.scoreA+it.second.scoreT*1.5;
        v.push_back(it.second);
    }
    sort(v.begin(),v.end(),cmp);
    cout<<v.size()<<"\n";
    int cnt = 1;
    for(int i=0;i<v.size();i++){
        if(i>=1&&v[i].sum!=v[i-1].sum)    cnt = i+1;
        cout<<cnt<<" "<<v[i].code<<" "<<v[i].sum<<" "<<v[i].num<<"\n";
    }
    return 0;
}
